# BETA M1 环境
HOST_DEV=m1
MONGO_DEV="mongodb://$(HOST_DEV):27017/klg-admin-dev"

# jenkins 测试环境
HOST_TEST=192.168.1.180
MONGO_TEST="mongodb://$(HOST_TEST):27017/klg-admin-test"

# BETA 环境
HOST_BETA=MONGO_HOST
MONGO_BETA="mongodb://$(HOST_BETA):27017/klg-admin-beta"


# install
install:
	npm i

# install 180
install180:
	@npm i --registry="http://$(HOST_TEST):7011"

# BETA测试
beta:
	MONGO_URI=$(MONGO_BETA) \
		npm start

# 180 BETA, 依赖 docker ，参数一致
b180:
	@MONGO_URI_DEV=$(MONGO_DEV) \
		nohup node dispath.js &

# ali 4 BETA测试
a4:
	MONGO_URI_DEV=$(MONGO_DEV) \
		npm start

### 测试
test: install
	MONGO_URI_TEST=$(MONGO_TEST) \
		npm test

test180: install180
	MONGO_URI_TEST=$(MONGO_TEST) \
		npm test

##########################
# 镜像相关
##########################
TAG=v0.1
ENV=beta
REGISTRY=r-klg.com
NAME=klg-admin-user
IMAGE=$(REGISTRY)/$(NAME):$(ENV)

# Dockerfile
build: 
	docker build -t $(IMAGE) .

tag:
	docker tag $(IMAGE) $(REGISTRY)/$(NAME):$(TAG) 

push:
	docker push $(IMAGE)

push-Tag:
	docker push $(REGISTRY)/$(NAME):$(TAG)

BTP: build tag push push-Tag

stop:
	docker stop $(NAME) &&\
	docker rm $(NAME)

run:
	docker run -d \
		--name $(NAME) \
		-p 9010:9010 \
		-v /var/data/log:/log \
		--link mongo-$(ENV):MONGO_HOST \
		-e LOG_DIR=/log \
		$(IMAGE)